package schoolWork.work05.Example4a;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//窗口自身类实现ActionListener接口
public class MyWindow extends JFrame implements ActionListener {
    JTextField text;
    MyWindow(){
        setLayout(new FlowLayout());
        text = new JTextField(10);
        add(text);
        text.addActionListener(this);
        setBounds(100,100,150,150);
        setVisible(true);
        validate();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        String str = e.getActionCommand();
        System.out.println(str);
        System.out.println(str.length()+"(包含空格字符)");
    }
}
